    /*
** test.c
** Login : <bredin76>
** Started on  Sat Feb 16 22:58:19 2008 xavier
** $Id$
**
** Author(s):
**  - xavier  <>
**
** Copyright (C) 2008 PHILIPPE Xavier
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <stdio.h>
#include "test.h"
extern GtkWidget *pProgress;
extern GtkWidget *pButton ;
extern GtkWidget *pButton2 ;
extern GtkWidget *expander ;
extern GtkWidget *pTerm ;
extern GtkWidget *pWindow;
extern gboolean   pResult ;
extern gboolean   bTest;
       GtkWidget *pAbout;

extern GtkWidget *pMenuItem1;
extern GtkWidget *pMenuItem2;
extern GtkWidget *pMenuItem3;

static void launch_install(int glitz, int force)
{
  system("killall cairo-dock");

  vte_terminal_fork_command(VTE_TERMINAL(pTerm),
                            NULL,
                            NULL,
                            NULL,
                            "~/",
                            FALSE,
                            FALSE,
                            FALSE);
 vte_terminal_feed_child(VTE_TERMINAL(pTerm), "cd /opt/cairo-dock\n", -1);
 //vte_terminal_feed_child(VTE_TERMINAL(pTerm), "./compil.sh -s;exit\n", -1);

 if (glitz && force)
   vte_terminal_feed_child(VTE_TERMINAL(pTerm), "gksudo ./cairo-dock_svn.sh --force-install --enable-glitz;exit\n", -1);
  //vte_terminal_feed_child(VTE_TERMINAL(pTerm), "./compil.sh -mg;exit\n", -1);

 else if (glitz)
   vte_terminal_feed_child(VTE_TERMINAL(pTerm), "gksudo ./cairo-dock_svn.sh --enable-glitz;exit\n", -1);
  //vte_terminal_feed_child(VTE_TERMINAL(pTerm), "./compil.sh -g;exit\n", -1);
 else if (force)
   vte_terminal_feed_child(VTE_TERMINAL(pTerm), "gksudo ./cairo-dock_svn.sh --force-install;exit\n", -1);
  //vte_terminal_feed_child(VTE_TERMINAL(pTerm), "./compil.sh -m;exit\n", -1);

 else
   //vte_terminal_feed_child(VTE_TERMINAL(pTerm), "./compil.sh;exit\n", -1);
vte_terminal_feed_child(VTE_TERMINAL(pTerm), "gksudo ./cairo-dock_svn.sh ; exit\n", -1);

  gtk_widget_set_sensitive(GTK_WIDGET(pButton2), 0);
  gtk_widget_set_sensitive(GTK_WIDGET(pButton), 0);
  gtk_widget_set_sensitive(GTK_WIDGET(pProgress),1);


}


void _on_terminal_text_changed(VteTerminal *vteterminal,
                                          gpointer     user_data)
{
  gtk_progress_bar_pulse(GTK_PROGRESS_BAR(pProgress));
}



void _on_terminal_child_exited(VteTerminal *vteterminal,
                                      gpointer     user_data)
{
  printf("child exited\n");

    g_spawn_command_line_async ("/opt/cairo-dock/script_cairo_dock_with_glitz.sh",
                                NULL);
  gtk_widget_set_sensitive(GTK_WIDGET(pProgress), 0);
  gtk_widget_set_sensitive(GTK_WIDGET(pButton), 1);
  gtk_widget_set_sensitive(GTK_WIDGET(pButton2), 1);
}



void OnAbout(GtkWidget* widget, gpointer data)
{
  GtkWidget *pApropos;

  pApropos = gtk_message_dialog_new (GTK_WINDOW(data),
                                   GTK_DIALOG_MODAL,
                                   GTK_BUTTONS_OK,
                                   GTK_MESSAGE_INFO,
                                   "Graphics by Bredin76 with CTAF's help \n Thanks to M@v for his script\n"
                                   "http://cairo-dock.necropotame.fr");

  gtk_dialog_run(GTK_DIALOG(pApropos));
  gtk_widget_destroy(pApropos);
}

void _on_click_start (GtkButton *button, gpointer data)
{
    gchar *message;
    gchar *messageUFT8;

    int glitz = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(pMenuItem1));
    int force = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(pMenuItem2));

    if ( force && glitz)
        message = g_strdup("cairo-dock sera recompile avec glitz\n\n Etes vous sur de vouloir continuer ? ");
    else if (glitz)
        message = g_strdup("cairo-dock sera installe avec glitz\n\n Etes vous sur de vouloir continuer ? ");
    else if (force)
        message = g_strdup("cairo-dock sera recompile \n\n Etes vous sur de vouloir continuer ? ");
    else
        message = g_strdup("cairo-dock sera installé sans options \n\n Etes vous sur de vouloir continuer ?");


    messageUFT8 = g_locale_to_utf8(message,-1,NULL,NULL,NULL);


    pAbout = gtk_message_dialog_new (GTK_WINDOW(pWindow),
                                    GTK_DIALOG_MODAL,
                                    GTK_MESSAGE_QUESTION,
                                    GTK_BUTTONS_YES_NO,
                                    messageUFT8);


       switch(gtk_dialog_run(GTK_DIALOG(pAbout)))
    {
        case GTK_RESPONSE_YES:
            /* OUI -> on quitte l application */
            launch_install(glitz,force);
            gtk_widget_destroy(pAbout);
            break;
        case GTK_RESPONSE_NO:
            /* NON -> on detruit la boite de message */
            gtk_widget_destroy(pAbout);
            break;
    }


}

void _on_click_uninstall(GtkButton *button, gpointer data )

{
      system("killall cairo-dock");
  vte_terminal_fork_command(VTE_TERMINAL(pTerm),
                            NULL,
                            NULL,
                            NULL,
                            "~/",
                            FALSE,
                            FALSE,
                            FALSE);
 vte_terminal_feed_child(VTE_TERMINAL(pTerm), "cd /opt/cairo-dock\n", -1);
 vte_terminal_feed_child(VTE_TERMINAL(pTerm), " ./cairo-dock_svn.sh --uninstall; exit;\n", -1);
}


void terminaiso()
{
      if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(pMenuItem3)))
  {
    g_spawn_command_line_async ("/opt/cairo-dock/script_cairo_dock_with_glitz.sh",
                                NULL);
    exit(0);//0 is success
  }
}


